package com.jemmyee.pizza.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.stereotype.Repository;

import com.jemmyee.core.dao.BaseDaoImpl;
import com.jemmyee.core.dao.Page;
import com.jemmyee.pizza.entity.ApplyComment;
import com.jemmyee.pizza.entity.Excerpt;
import com.jemmyee.pizza.entity.ExcerptStatistic;

/**
 * @author qiuchao
 * 2010-12-21
 */
@Repository("excerptDao")
public class ExcerptDaoImpl extends BaseDaoImpl<Excerpt> implements IExcerptDao {

	public void saveOrUpdateAll(List<Excerpt> excerpts) {
		getHibernateTemplate().saveOrUpdateAll(excerpts);
	}
	public ExcerptStatistic getExcerptStatisticByTerm(String sql){
		Connection conn = null ;
		Statement stat = null ;
		ResultSet rs = null ;
		ExcerptStatistic s = new ExcerptStatistic();
		try {
			conn = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
			stat = conn.createStatement();
			rs = stat.executeQuery(sql);
			while(rs.next()){
				s.setTotalPerson(Integer.parseInt(rs.getString(1)));
				s.setTotalGasAmount(Float.parseFloat(rs.getString(2)));
				s.setTotalMoney(Float.parseFloat(rs.getString(3)));
				s.setNotMoney(Float.parseFloat(rs.getString(4)));
				s.setHasMoney(Float.parseFloat(rs.getString(5)));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return s;
	}
	
}
